﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace dodone
{
	/// <summary>
	/// Interaction logic for ProjectControl.xaml
	/// </summary>
	public partial class ProjectControl : UserControl
	{
		public ProjectControl()
		{
			InitializeComponent();
		}

		public static DependencyProperty TitleProperty =
			DependencyProperty.Register("Title", typeof(string),
			typeof(ProjectControl));

		public string Title
		{
			get { return (string)GetValue(TitleProperty); }
			set { SetValue(TitleProperty, value); }
		}

		private void mnuProject_MouseDoubleClick(object sender, MouseButtonEventArgs e)
		{
			mnuProject.Visibility = Visibility.Hidden;
			tbxProject.Visibility = Visibility.Visible;
			tbxProject.Focus();
		}

		private void tbxProject_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.Key == Key.Enter)
				RenamingComplete();
		}

		private void tbxProject_LostFocus(object sender, RoutedEventArgs e)
		{
			RenamingComplete();
		}

		private void tbxProject_GotFocus(object sender, RoutedEventArgs e)
		{
			tbxProject.SelectAll();
		}

		private void RenamingComplete()
		{
			mnuProject.Visibility = Visibility.Visible;
			tbxProject.Visibility = Visibility.Hidden;
		}
	}
}
